<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class IndexController extends Controller
{
    //
    public function getDetail($rid,Request $req)
    {
        $data = DB::table('recruit as rec') 
                -> leftJoin('regioncate as reg','rec.r_id','=','reg.id')
                -> leftJoin('cate as p','rec.p_id','=','p.id')
                -> leftJoin('cate as c','rec.c_id','=','c.id')
                -> leftJoin('we as w','rec.w_id','=','w.id')
                -> leftJoin('er','rec.er_id','=','er.id')
                -> leftJoin('pms','rec.pms_id','=','pms.id')
                -> leftJoin('enterprises as ent','rec.e_id','=','ent.id')
                -> select('rec.*','reg.name','ent.address','p.name as pN','c.name as cN','w.value as wN','er.value as erN','pms.value as pmsN','ent.compname','ent.corpsize','ent.corptype','ent.firstIndustry')
                -> where('rec.id',$rid)
                -> first();
        $ent=DB::table('enterprises as ent') 
                -> leftJoin('corpsize as cor','ent.corpsize','=','cor.id')
                -> leftJoin('corptype as ct','ent.corptype','=','ct.id')
                -> leftJoin('industrycate as ind','ent.firstIndustry','=','ind.id')
                -> leftJoin('regioncate as reg','ent.province','=','reg.id')
                -> leftJoin('regioncate as regi','ent.city','=','regi.id')
                -> select('cor.name as corN','ct.name as ctN','ind.name as indN','ent.*','regi.name as cityN','reg.name as priN')
                -> where('cor.id',$data->corpsize)
                -> where('ct.id',$data->corptype)
                -> where('ind.id',$data->firstIndustry)
                -> first();
               // 最新职位推荐
        $newData = DB::table('recruit as rec') 
                -> leftJoin('regioncate as reg','rec.r_id','=','reg.id')
                -> leftJoin('enterprises as ent','rec.e_id','=','ent.id')
                -> select('rec.id','rec.workname','ent.compname','reg.name')
                -> where('rec.c_id',$data -> c_id)
                -> get();
        // dd($newData);
        $labeld = DB::table('recruit_label as r')
                -> leftJoin('label as l','r.l_id','=','l.id')
                -> where('r.rec_id',$rid)
                -> get();
        // dd($ent);
        $data -> corpsize = $ent -> corN;
        $data -> corptype = $ent -> ctN;
        $data -> firstIndustry = $ent -> indN;
        
        // dd($ent);
        // dd(session('master['.$eid.']') -> lxfs);
        preg_match('/\">(.*?)<\/a>/', $ent -> lxfs,$macth);
        // dd($macth);
        $page = 'http:';
        if(empty($macth[1]))
        {
            $macth[1]=null;
        }
        // dd($data);
        return view('home.jobsearch.detail',['data' => $data,'ent' => $ent,'labeld' => $labeld,'page' => $macth[1]]);
    }

    public function postAjaxjl(Request $request)
    {
        // dd($request -> all());
        if(session('user')['is_login']=1 && !empty(session('user')['is_login']))
        {

        $data['ent_id']=$request->en;
        $data['rec_id']=$request->re;
        $data['int_id']=session('user')['id'];
        $data['res_id']=DB::table('resume')->where("inter_id",$data['int_id'])->first()->id;
        $data['status']=0;
        
        $res=DB::table('resume_recruit')->insert($data);
        if($res)
        {
            return response()->json(1);
        }else
        {
            return response()->json(0);
        }

        }else
        {
            return response()->json(2);
        }
       

    }
}
